package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.ProductService;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lkl
 * @since 2025/4/1
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @PostMapping("/add")
    public ResponseData add(@RequestBody JSONObject param, @IRequestToken String token) {
        productService.addProduct(param);
        return ResponseData.success();
    }

    @PostMapping("/modify")
    public ResponseData update(@RequestBody JSONObject param, @IRequestToken String token) {
        productService.updateProduct(param);
        return ResponseData.success();
    }

    @GetMapping("/del")
    public ResponseData delete(@IRequestParam JSONObject param, @IRequestToken String token) {
        productService.deleteProduct(param);
        return ResponseData.success();
    }

    @GetMapping("/detail")
    public ResponseData detail(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(productService.detail(param));
    }

    @GetMapping("/detailWithParam")
    public ResponseData detailWithParam(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(productService.detailWithParam(param));
    }

    @GetMapping("/modifyPrice")
    public ResponseData modifyPrice(@IRequestParam JSONObject param, @IRequestToken String token) {
        productService.modifyPrice(param);
        return ResponseData.success();
    }

    @GetMapping("/operationProduct")
    public ResponseData operationProduct(@IRequestParam JSONObject param, @IRequestToken String token) {
        productService.operationProduct(param);
        return ResponseData.success();
    }

    @GetMapping("/listProduct")
    public ResponseData listProduct(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(productService.listProduct(param, token));
    }
}
